package Exam;

import java.util.Scanner;

/**
 * @Author Kechelle
 * @Date 2020/9/26 19:44
 * @Version 1.0
 */
public class ClassThree {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        String[] res = str.split(",");
        int m = Integer.parseInt(res[0]);
        int n = Integer.parseInt(res[1]);
        int[][] grid = new int[m][n];
        for (int i=0;i<m;i++){
            for (int j=0;j<n;j++){
                grid[i][j] = scanner.nextInt();
            }
        }
        System.out.println(fuction(grid));
    }

    public static int fuction(int[][] grid){
        int m = grid.length,n=grid[0].length;
        for (int j=1;j<n;j++){
            grid[0][j] += grid[0][j-1];
        }
        for (int i=1;i<m;i++){
            grid[i][0] += grid[i-1][0];
        }
        for (int i=1;i<m;i++){
            for (int j=1;j<n;j++){
                grid[i][j] += Math.max(grid[i][j-1],grid[i-1][j]);
            }
        }
        return grid[m-1][n-1];
    }
}
